package com.mazaiting.websocket.service.impl;

import com.mazaiting.websocket.server.WebSocketServer;
import com.mazaiting.websocket.service.TestService;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 测试服务实现
 *
 * @author mazaiting
 * @create_time 2022/4/19 17:45
 */
@Service
@EnableScheduling
public class TestServiceImpl implements TestService {

    @Override
    @Scheduled(fixedRate = 1000) //1000毫秒执行一次
    public void printTime() {
        SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
        String date = dateFormat.format(new Date());
        WebSocketServer.sendInfo(date, "10");
        System.out.println(date);
    }
}
